package homework;

import java.util.HashSet;
import java.util.Iterator;
//定义一个Course类，代表课程；定义一个Student类，代表学生，
//在Student类中包含一个属性是一个HashSet的对象，用来存储该学生所选的所有课程，
//并提供相应的addCourse(Course c)方法和removeCourse(String name)方法，
//表示添加一门选课和删除一门选课（删除选课时通过传课程名参数来确定）。
public class Student {
	private HashSet<Course> students = new HashSet<Course>();
	private String sname;
	private int id;
	
	public Student(){}
	
	public HashSet<Course> getStudents() {
		return students;
	}

	public void setStudents(HashSet<Course> students) {
		this.students = students;
	}

	public void setSname(String sname){
		this.sname=sname;
	}
	public String getSname(){
		return sname;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void addCourse(Course c){
		students.add(c);
	}
	
	public void removeCourse(String name){
		Iterator<Course> iterator = students.iterator();
		while(iterator.hasNext()){
			Course course = iterator.next();
			if(course.getName().equals(name)){
				iterator.remove();
			}
		}
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.students.toString();
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return id;
	}


	
}
